#include<stdio.h>
#include<stdlib.h>
#include<unistd.h>

#include<sys/types.h>
#include<sys/wait.h>
int main()
{
	pid_t id = fork();
	if(id == 0)
	{
		printf("我是子进程，id：%d\n",getpid());
		sleep(4);
	}
	else
	{
		int status = 0;
		pid_t reti = wait(&status);
		if(reti != 0 && (status & 0x7F) == 0)
		{
			printf("子进程：%d 正常退出，退出码：%d\n",reti,(status>>8)&0xff);
		}
		else if(reti > 0) //返回-1为异常终止，但由于进程退出码是整型但只有低八位存储，最终我们拿到的进程退出码为255
		{
			printf("信号：%d\n",status & 0x7F);
		}
	}
}	
